home *** CD-ROM | disk | FTP | other *** search
- /********************************************************************************
-
- Gnucleus - A node application for the Gnutella network
- Copyright (C) 2000 John Marshall
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
- For support, questions, comments, etc...
- E-Mail:
- Steve Kemp <skx@tardis.ed.ac.uk>
-
- Address:
- Private ;)
-
- ********************************************************************************/
-
- // ViewSearchSpy.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "Gnucleus.h"
- #include "MainFrm.h"
-
- #include "GnucleusDoc.h"
- #include "ViewTransfer.h"
- #include "ViewSearchSpy.h"
-
- #include "IPFilter.h"
-
- #include "GnuTransfer.h"
- #include "GnuHash.h"
- #include "GnuSock.h"
- #include "GnuControl.h"
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewSearchSpy
-
- IMPLEMENT_DYNCREATE(CViewSearchSpy, CFormView)
-
- CViewSearchSpy::CViewSearchSpy()
- : CFormView(CViewSearchSpy::IDD)
- {
- //{{AFX_DATA_INIT(CViewSearchSpy)
- //}}AFX_DATA_INIT
-
- m_paused = false;
- }
-
- CViewSearchSpy::~CViewSearchSpy()
- {
- }
-
- void CViewSearchSpy::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CViewSearchSpy)
- DDX_Control(pDX, IDC_LIST_SEARCH_RESULTS, m_lstResults);
- //}}AFX_DATA_MAP
- }
-
-
- BEGIN_MESSAGE_MAP(CViewSearchSpy, CFormView)
- //{{AFX_MSG_MAP(CViewSearchSpy)
- ON_WM_SIZE()
- ON_BN_CLICKED(IDC_PAUSE_RESUME, OnPauseResume)
- ON_BN_CLICKED(IDC_COPY_SEARCH, OnCopySearch)
- ON_NOTIFY(NM_DBLCLK, IDC_LIST_SEARCH_RESULTS, OnDblclkListSearchResults)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewSearchSpy diagnostics
-
- #ifdef _DEBUG
- void CViewSearchSpy::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CViewSearchSpy::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CViewSearchSpy message handlers
-
- void CViewSearchSpy::OnInitialUpdate()
- // Initializes all the dialog controls on the local view
- {
- CFormView::OnInitialUpdate();
-
- Doc = (CGnucleusDoc *) GetDocument();
- Comm = Doc->GnuComm;
-
- CRect rect;
- m_lstResults.GetWindowRect(&rect);
-
- m_lstResults.InsertColumn( 0, "Terms" );
- m_lstResults.SetColumnWidth(-1, LVSCW_AUTOSIZE_USEHEADER);
-
- m_lstResults.SetExtendedStyle(LVS_EX_FULLROWSELECT);
-
- GetParentFrame()->GetClientRect(&rect);
- OnSize(SIZE_RESTORED, rect.right - 4, rect.bottom - 4);
-
- }
-
-
- void CViewSearchSpy::OnSize(UINT nType, int cx, int cy)
- // Adjusts dialog controls when window in resized
- {
- // Make sure dialog controls exist
- if(m_lstResults.m_hWnd != NULL)
- {
- CRect rect;
- GetClientRect( &rect );
-
- // We only have one column, so make it full width.
- // (Do this before we modify the rect.)
- m_lstResults.SetColumnWidth( 0, rect.Width() - 6 );
-
- CRect pauseBtn;
- ::GetClientRect(GetDlgItem( IDC_PAUSE_RESUME )->GetSafeHwnd(), &pauseBtn );
- CRect copyBtn;
- ::GetClientRect(GetDlgItem( IDC_COPY_SEARCH )->GetSafeHwnd(), ©Btn );
-
- // List fills the whole window, except for the bottom row, which is
- // as big as the height of the pause button
- rect.bottom -= pauseBtn.Height();
-
- m_lstResults.MoveWindow( rect );
-
- rect.top = rect.bottom;
- rect.bottom += pauseBtn.Height();
- rect.right = pauseBtn.Width();
- GetDlgItem( IDC_PAUSE_RESUME )->MoveWindow( rect );
-
- int height = 0;
- int width = 0;
- height = copyBtn.Height();
- width = copyBtn.Width();
-
- copyBtn.top = rect.top;
- copyBtn.bottom = copyBtn.top + height;
- copyBtn.left = rect.right + 4;
- copyBtn.right = copyBtn.left + width;
-
- GetDlgItem( IDC_COPY_SEARCH )->MoveWindow( copyBtn );
-
- }
-
- CFormView::OnSize(nType, cx, cy);
- }
-
-
- /**
- * Add the search request to the list window, unless we're
- * paused.
- */
- void CViewSearchSpy::AddSearchTerm( CString searchText )
- {
- int item_count = 0;
- if ( !m_paused )
- {
- while((item_count = m_lstResults.GetItemCount()) + 1 > m_lstResults.GetCountPerPage() && item_count )
- {
- m_lstResults.DeleteItem(item_count - 1);
- }
- m_lstResults.InsertItem( 0, searchText );
- }
- }
-
- /**
- * Toggle the updating of the list.
- */
- void CViewSearchSpy::OnPauseResume()
- {
- if ( m_paused )
- {
- GetDlgItem( IDC_PAUSE_RESUME )->SetWindowText( "Pause" );
- m_paused = false;
- }
- else
- {
- GetDlgItem( IDC_PAUSE_RESUME )->SetWindowText( "Resume" );
- m_paused = true;
- }
- }
-
-
- /**
- * Start a search that is the same as that which is currently
- * selected.
- */
- void CViewSearchSpy::OnCopySearch()
- {
- CString TestCase, Keyword, Speed;
-
- CComboBox *cbKeyword = (CComboBox *) ( (CMainFrame *) AfxGetMainWnd() )->GetDialogBar()->GetDlgItem(IDC_COMBO_SEARCH);
-
- int nSelected = m_lstResults.GetNextItem( -1, LVNI_ALL | LVNI_SELECTED);
- if ( nSelected == -1 )
- return;
-
- Keyword = m_lstResults.GetItemText( nSelected, 0);
-
- CString Search = "Searching for \"";
- Search += Keyword;
- Search += "\"";
-
-
- // Make sure search isnt null
- if(Keyword == "")
- return;
-
- if(TestCase != Keyword)
- cbKeyword->InsertString(0, Keyword);
-
- // Bring window to front if it already exists
- bool Found = 0;
- CString Title;
- POSITION pos = ((CGnucleusApp *) AfxGetApp())->MasterDoc->GetFirstViewPosition();
-
- while (pos != NULL)
- {
- CView* pView = ((CGnucleusApp *) AfxGetApp())->MasterDoc->GetNextView(pos);
- pView->GetParentFrame()->GetWindowText(Title);
-
- if(Title == Search)
- {
- pView->GetParentFrame()->BringWindowToTop();
-
- return;
- }
- }
-
- // Create new search window
- CFrameWnd* pNewFrame = ((CGnucleusApp *) AfxGetApp())->m_pSearchViewTemplate->CreateNewFrame(((CGnucleusApp *) AfxGetApp())->MasterDoc, NULL);
-
- pNewFrame->ModifyStyle(FWS_ADDTOTITLE, 0);
- pNewFrame->SetWindowText(Search);
-
- ((CGnucleusApp *) AfxGetApp())->m_pSearchViewTemplate->InitialUpdateFrame(pNewFrame, ((CGnucleusApp *) AfxGetApp())->MasterDoc);
-
- }
-
- //
- // A double-click on a search term is synonymous with a
- // copy search request.
- void CViewSearchSpy::OnDblclkListSearchResults(NMHDR* pNMHDR, LRESULT* pResult)
- {
- OnCopySearch();
- *pResult = 0;
- }
-